﻿using SIE.SCADA.Database.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SIE.SCADA.Database;

namespace SIE.SCADA.ZemtDemo.Common
{
    public abstract class ConfigBase
    {
        //private string _serverName;
        protected string _dbName;
        //private string _userName;
        //private int _timeout;

        protected int _portNo;
        public IDBClient DBClient { get; protected set; }

        public string ServerName { get; set; }
        public string DbName { get; set; }

        public string UserName { get; set; }
        public string Password { get; set; }

        public int PortNo { get; set; }

        public bool UnAdmin { get; set; }

        public int Timeout { get; set; }

        public string ClientProviderString { get; set; }

        public string ConfigProviderString { get; set; }

        public string LogProviderString { get; set; }
        public abstract IDBClient GetClient();

        public ConfigBase()
        {
            Init();
        }

        protected abstract void Init();

        public IDBClient CreateDBClient(IConnectionConfig connectionConfig)
        {
            DatabaseConfig DatabaseConfig = new DatabaseConfig();
            DatabaseConfig.Config = connectionConfig;
            DatabaseConfig.ClientProviderString = ClientProviderString;
            DatabaseConfig.ConfigProviderString = ConfigProviderString;
            DatabaseConfig.LogProviderString = LogProviderString;
            var DBClient = DatabaseConfig.CreateClient();
            // Logger.Info($"CreateDBClient:{DBClient.Configuration.DatabaseName}");
            return DBClient;
        }
    }
}
